<template>
  <div style="height: 100%;">
    <div class="container">
      <div class="main">
        <h1>信息采集智能管理系统</h1>
        <div class="login-box">
          <div><span>登录</span></div>
          <el-form status-icon ref="loginForm" label-width="100px" class="demo-ruleForm" :rules="rules"
            :model="userInfo">
            <el-form-item label="用户名" prop="username">
              <el-input v-model="userInfo.username"></el-input>
            </el-form-item>
            <el-form-item  label="密码" prop="password">
              <el-input type="password" v-model="userInfo.password"></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="captcha" style="width:225px">
              <el-input v-model="userInfo.captcha"></el-input>

            </el-form-item>

            <el-form-item>
              <!-- <div Coclass="code" @click="refreshde">
                <SIdentify :identifyCode="identifyCode"></SIdentify>
                
              </div> -->
              <div class="code">

                <img :src="captchaPath" @click="getCaptcha">
              </div>
              <el-button type="primary" style="" id="login" @click="login">登录</el-button>

            </el-form-item>
          </el-form>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import SIdentify from "../untils/identify.vue";
import { getUUID } from "../untils/uuId.js";
export default {
  data() {
   
    return {
      captchaPath: "",
      userInfo: {
        username: "",
        password: "",
        // verifyCode: "",
        uuid: "",
        captcha:''
      },
      // identifyCodes: "1234567890",
      // identifyCode: "",

      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "请输入正确用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        // verifyCode: [{ validator: validateCode, trigger: "blur" }],
        captcha: [
          { required: true, message: "请输入验证码", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getCaptcha();
  },
  methods: {
    getCaptcha() {
      this.userInfo.uuid = getUUID();
      this.captchaPath = `http://gather.dfinfo.net.cn/gather-admin/captcha?uuid=${this.userInfo.uuid}`;
    },
    login() {
      this.$refs.loginForm.validate(async valid =>{
        if(!valid) return
         const {data:res} = await this.$http.post('/login',this.userInfo)
        if(res.code!=0) {
          this.getCaptcha()
          return this.$message.error(res.msg)
        }
        // 将登录之后返回的token值存入到客户端的sessionStorage
        window.sessionStorage.setItem('token',res.data.token)
        // 跳转到后台主页
        this.$router.push('/home')
      })
    }
  }
}
    

</script>
<style lang="scss" scoped>
.container {
  height: 100%;
  background-image: url("../assets/login/pexels-rodnae-productions-7947669.jpg");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .main {
    width: 500px;
    height: 600px;

    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    h1 {
      text-align: center;
      color: rgb(69, 71, 71);
    }
    .login-box {
      height: 400px;
      background-color: white;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      border-radius: 5%;

      span {
        font-size: 20px;
      }
      .el-form {
        width: 450px;
        margin-right: 70px;
        #login {
          width: 100%;
        }
        .code {
          // width: 114px;
          // height: 40px;
          
          position: absolute;
          right: 20px;
          bottom: 40px;
        }
      }
    }
  }
}
</style>